package com.hengpeng.itfinoss.service.userLevelSet.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import com.hengpeng.common.exception.ServiceResult;
import com.hengpeng.common.persist.QueryResult;
import com.hengpeng.common.persist.query.DynamicQuery;
import com.hengpeng.itfinbase.en.LevelType;
import com.hengpeng.itfinbase.en.UserLevel;
import com.hengpeng.itfinbase.persist.UserLevelSet;
import com.hengpeng.itfinoss.service.ServiceFactory;
import com.hengpeng.itfinoss.service.userLevelSet.UserLevelSetSrervice;

/**
 * 会员等级service实现层
 * 
 * @author liyangyang
 *
 */
@Service
@Lazy
public class UserLevelSetServiceImpl implements UserLevelSetSrervice {
    @Autowired
    private ServiceFactory serviceFactory;

    @Override
    public ServiceResult<List<UserLevelSet>> selectUserLevelSetPage(UserLevel userLevel, LevelType levelType,
            int indexPage, int pageSize) {

        DynamicQuery query = new DynamicQuery(UserLevelSet.class);
        if (userLevel != null) {
            query.eq("userLevel", userLevel);
        }
        if (levelType != null) {
            query.eq("levelType", levelType);
        }
        query.setIsSearchTotalCount(true);
        query.setPageIndex(indexPage);
        query.setPageSize(pageSize);
        query.desc("createTime");
        QueryResult<UserLevelSet> requery = serviceFactory.getPersistService().findWithPage(UserLevelSet.class, query);
        ServiceResult<List<UserLevelSet>> result = new ServiceResult<List<UserLevelSet>>(requery.getResults());
        result.setReturnListSize((int) requery.getTotalCount());
        return result;
    }

    @Override
    public UserLevelSet updateUserLevelSetById(UserLevelSet userLevelSet) {

        return serviceFactory.getPersistService().update(userLevelSet);
    }

}
